﻿//这里的代码，是此控件操作复选择框的，主要作用是当父结点被选择时，子结点根着对应变化
var ignoreEvents = false;
var tree = null;
var selectTBS = '';
function nodeEventHandler(treeview, node, eventType) {
    if (!tree) {
        tree = treeview;
    }
    if (ignoreEvents) return;
    ignoreEvents = true;
    if (eventType == "checked") {
        setChildrenCheckBox(node, true);
       //setStatic(node.getValue(),true);
    } else if (eventType == "unchecked") {
        setChildrenCheckBox(node, false);
        //setStatic(node.getValue(),false);
    }
    //    else if (eventType == "expanded") {
    //        node.setImageUrl('../images/topo/operation/folder_open.gif');
    //    } else if (eventType == "collapsed") {
    //        node.setImageUrl('../images/topo/operation/folder.gif');
    //    }
    ignoreEvents = false;
}
function setChildrenCheckBox(parentNode, value) {
    var childNodes = parentNode.getChildNodes();
    for (var i = 0; i < childNodes.length; i++) {
        var node = childNodes[i];
        node.setChecked(value);
        if (value) { //选中就直接加在字符串后面
            selectTBS += node.getValue() + ',';
        }
        else {
            selectTBS.replace(node.getValue() + ',', ''); //取消选择就替换字符串中该基站TBS           
        }
        setStatic(node.getValue(), value);
        setChildrenCheckBox(node, value);        
    }
    if (childNodes.length == 0) {
        parentNode.setChecked(value);
        selectTBS = selectTBS.replace(new RegExp(parentNode.getValue() + ',', 'g'), ''); //取消选择就替换字符串中该基站TBS
        if (value) { //选中就直接加在字符串后面
            selectTBS += parentNode.getValue() + ',';
        }
        setStatic(parentNode.getValue(), value);
    }
    setSelectedTBSToCookie(selectTBS);
}
function setParentCheckBox(node, value) {
    var parentNode = node.getParent();
    if (parentNode == null) return;
    parentNode.setChecked(value);
    if (!value || allSiblingChecked(parentNode))
        setParentCheckBox(parentNode, value);
}
function allSiblingChecked(node) {
    var nodes = node.getSiblingNodes();
    for (var i = 0; i < nodes.length; i++) {
        if (!nodes[i].getChecked())
            return false;
    }
    return true;
}
function setNodeUnCheck(nodeid) {
    tree.findByValue(nodeid)[0].setChecked(false);
}


/*将选中的基站TBS字符串保存到COOKIE中*/
function setSelectedTBSToCookie() {
    window.parent.SetCookie('zhwg_TBSMainChannel', selectTBS);
}

function setStatic(neid, isAdd) {
    setSelectedTBSToCookie();
    window.parent.document.getElementById('ImpMonitorIndexRight').contentWindow.addPannel(neid,isAdd);
}
/*设置节点选中*/
function setNodeChecked(treeview) {
    if (!tree) {
        tree = treeview;
    }
    var selectedTBS = window.parent.GetCookie('zhwg_TBSMainChannel');
    if (selectedTBS) {
        selectedTBS = selectedTBS.replace(/;/g, '');
        selectTBS = selectedTBS;
        var nodes = treeview.getNodes();
        for (var i = 0, length = nodes.length; i < length; i++) {
            var childNodes = nodes[i].getChildNodes();
            for (var j = 0, count = childNodes.length; j < count; j++) {
                if (selectedTBS.indexOf(childNodes[j].getValue() + ',') > -1) {
                    setChildrenCheckBox(childNodes[j], true);
                    selectedTBS = selectedTBS.replace(new RegExp(childNodes[j].getValue() + ',', 'g'), '');
                }
            }
        }
    }
}